package com.lizx.persional.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.lizx.persional.dao.DepartmentDao;
import com.lizx.persional.dao.UserInfoDao;
import com.lizx.persional.entity.Users;
import com.lizx.persional.dao.UsersDao;
import com.lizx.persional.service.UsersService;
import com.lizx.persional.common.base.SuperServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 李振兴
 * @since 2018-02-27
 */
@Service
public class UsersServiceImpl extends SuperServiceImpl<UsersDao, Users> implements UsersService {

    @Autowired
    private UsersDao usersDao;
    @Autowired
    private UserInfoDao userInfoDao;
    @Autowired
    private DepartmentDao departmentDao;
    /**
     * 根据用户名查找
     *
     * @param loginName
     * @return
     */
    @Override
    public Users selectByLoginName(String loginName) {
        EntityWrapper<Users> ew = new EntityWrapper<>();
        ew.eq("login_name",loginName);
        Users user = usersDao.getUserByLoginName(loginName);
        user.setUserInfo(userInfoDao.selectByUserId(user.getId()));
        user.setDepartmentName(departmentDao.selectById(user.getDepartmentId()).getName());
        return  user;
    }
}

